//查看更多
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

class AcgShowMoreTextWidget extends StatefulWidget {
  final String? summary;

  final int? maxLine;
  final double? maxWidth;
  final txColor;

  AcgShowMoreTextWidget({
    super.key,
    this.summary,
    this.maxLine = 3,
    this.maxWidth,
    this.txColor = const Color(0xff989898),
  });

  @override
  State<AcgShowMoreTextWidget> createState() => _AcgShowMoreTextWidgetState();
}

class _AcgShowMoreTextWidgetState extends State<AcgShowMoreTextWidget> {
  RxDouble turnsObx = RxDouble(1.0); //翻转动画参数

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Obx(() {
          bool turn = turnsObx.value % 1 == 0;
          return Column(
            children: [
              Text(
                widget.summary?.isNotEmpty == true ? widget.summary ?? '' : '暂无简介',
                style: textStyle(12, widget.txColor, FontWeight.w400),
                maxLines: turn ? widget.maxLine : null,
                overflow: turn ? TextOverflow.ellipsis : null,
              ),
              if (showMoreText())
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () => onChangeExpand(),
                      child: Obx(() => Padding(
                            padding: EdgeInsets.symmetric(vertical: 12),
                            child: Row(
                              children: [
                                Text(
                                  turn ? '更多简介' : '收起简介',
                                  style: textStyle(12, Color(0xffEFEFEF), FontWeight.w400),
                                ),
                                2.sizeBoxW,
                                AnimatedRotation(
                                  turns: turnsObx.value,
                                  duration: Duration(milliseconds: 300),
                                  child: Image.asset(
                                    'acg_narrow.png'.acgImgPath,
                                    width: 18,
                                    color: Color(0xffDCDCDC),
                                  ),
                                ),
                              ],
                            ),
                          )),
                    )
                  ],
                ),
            ],
          );
        }),
      ],
    );
  }

  //展开方式
  onChangeExpand() => turnsObx.value = turnsObx.value + 0.5;

  //是否显示
  bool showMoreText() {
    return textExceedMaxLines(
      widget.summary ?? '.',
      textStyle(12, Color(0xffEFEFEF), FontWeight.w400),
      widget.maxLine ?? 3,
      widget.maxWidth ?? Get.width,
    );
  }
}
